<template>
    <el-date-picker :type="type" :value="model" :placeholder="placeholder" style="width: 200px"></el-date-picker>
</template>
<script>
export default {
    name: 'defaultdatepicker',
    props: {
        type: {
            type: String,
            default () {
                return "date";
            }
        },
        placeholder: {
            type: String,
            default () {
                return "";
            }
        },
        value: {
            type: String,
            default () {
                return "";
            }
        }
    },
    data() {
        return {
            model: this.value,
        }
    },
    watch: {
        model(val) {
            let finalVal = val.format("yyyy-MM-dd");
            if(this.type === 'year') {
                finalVal = val.getFullYear();
            } 
            else if(this.type === 'month') {
                finalVal = val.format("yyyy-MM");
            }
            this.$emit('input', finalVal + "");//emit返回必须是String
        }
    },
    mounted() {
        this.$nextTick(() => {
            if (!this.value || this.value === "") {
                let date = new Date();
                this.model = date;
            } else {
                this.model = new Date(this.value);
            }
        });
    },
    methods: {
        
    }
}
</script>